<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .animate-ele {
        position: relative;
        width: 100px;
        height: 100px;
        background: red;
    }
    * {
        font-size: 28px;
    }
</style>

<body>
    <div id="animateEle" class="animate-ele"></div>
    <button id="start">开始</button>
    <script>

        const element = document.getElementById('animateEle');
        let count=0;
        function step() {
            count++;
           
            if(count<500){
                element.style.transform = 'translateX(' + count + 'px)';
                window.requestAnimationFrame(step);
            }
        }

        start.onclick=function(){
            window.requestAnimationFrame(step);
        }
       
    </script>
</body>

</html>